import request from './requestAdmin'
import storageService from '../utils/storageService'
import {URL} from '../utils/url'
import axios from 'axios'

//登录
export function login({email,password,checkPass}) {
    return request.post('admin/login',{email,password,checkPass})
}

//获取用户列表
export function getUserList(page,page_size){
    const url = URL + 'api/admin/user/get'
    const data ={
      'page': page,
      'page_size':page_size
    }
    const headers ={
        'Authorization': 'Bearer ' + storageService.get(storageService.ADMIN_TOKEN)
    }
    return axios.get(url,{
      params: data,
      headers:headers
    }).then(res => {
      return Promise.resolve(res)
    })
}

//设为管理
export function setAdmin({id}) {
    return request.post('admin/add',{id})
}

//移除管理
export function deleteAdmin({id}) {
  return request.post('admin/delete',{id})
}

//修改用户
export function modifyUser({id,email,name,sign}) {
  return request.post('admin/user/modify',{id,email,name,sign})
}

//删除用户
export function deleteUser({id}) {
    return request.post('admin/user/delete',{id})
}

//获取视频列表
export function getVideoList(page,page_size){
  const url = URL + 'api/admin/video/get'
  const data ={
    'page': page,
    'page_size':page_size
  }
  const headers ={
      'Authorization': 'Bearer ' + storageService.get(storageService.ADMIN_TOKEN)
  }
  return axios.get(url,{
    params: data,
    headers:headers
  }).then(res => {
    return Promise.resolve(res)
  })
}

//修改视频
export function modifyVideo({id,title,content,isShow}) {
  return request.post('admin/video/modify',{id,title,content,isShow})
}

//删除视频
export function deleteVideo({id}) {
  return request.post('admin/video/delete',{id})
}

//获取通知
export function getAnnounceList(page,page_size){
  const url = URL + 'api/admin/announce/get'
  const data ={
    'page': page,
    'page_size':page_size
  }
  const headers ={
      'Authorization': 'Bearer ' + storageService.get(storageService.ADMIN_TOKEN)
  }
  return axios.get(url,{
    params: data,
    headers:headers
  }).then(res => {
    return Promise.resolve(res)
  })
}

//删除通知
export function deleteAnnounce({id}) {
  return request.post('admin/announce/delete',{id})
}

//添加通知
export function addAnnounce({title,content,url}) {
  return request.post('admin/announce/add',{title,content,url})
}

//获取轮播图
export function getCarouselList(){
  const url = URL + 'api/carousel/get'
  return axios.get(url).then(res => {
    return Promise.resolve(res)
  })
}

//添加轮播图
export function addCarousel({title,img,url}) {
  return request.post('admin/carousel/upload',{title,img,url})
}

//删除轮播图
export function deleteCarousel(id) {
  return request.post('admin/carousel/delete',{id})
}